<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport"
			content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
		<style type="text/css">
			td .layui-table-cell {
				text-align: center;
				height: 150px;
				white-space: normal;
			}

			.layui-table img,
			.layui-table video {
				width: 50px;
				max-width: 60px;
			}

			td .layui-table-cell {
				text-align: center;
				height: 120px;
				vertical-align: middle;
				white-space: normal;
			}

			.tDiv {
				font-size: 10px;
				line-height: 15px;
				text-align: left;
			}

			.tDiv-price {
				font-size: 10px;
				line-height: 13px;
			}
		</style>
	</head>

	<body>

		<div class="layui-fluid">
			<div class="layui-card">
				<div class="layui-card-header table-operate-btn">
					<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='alladd'>添加商品信息</button>
					<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='del'>删除商品信息</button>
					<!--<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='copy'>拷贝当前店铺商品信息</button>-->
					是否启用：
					<button class="layui-btn layui-btn-danger layui-btn-sm" data-type='off'>一键禁用</button>
					<button class="layui-btn layui-btn-container layui-btn-sm" data-type='on'>一键启用</button>
					是否推荐：
					<button class="layui-btn layui-btn-danger layui-btn-sm" data-type='off_recommend'>一键取消</button>
					<button class="layui-btn layui-btn-container layui-btn-sm" data-type='on_recommend'>一键推荐</button>
					<!-- <button class="layui-btn layui-btn-container layui-btn-sm" data-type='on_daoru'>一键导入</button> -->
					<button id="importbill" class="layui-btn layui-btn-normal layui-btn-sm"
								data-type='importdata'>导入</button>
					<!-- <button class="layui-btn layui-btn-primary layui-btn-sm" data-type='edit'>一键编辑</button> -->
				</div>
				<div class="layui-card-body">
					<div class="layui-row layui-col-space15">
						<div class="layui-btn-sm2 layui-col-md2 layui-col-xs2">
							<div id="test9" class="demo-tree demo-tree-box" style="width: 100%; height: 100%;"></div>
						</div>
						<div class="layui-btn-sm10 layui-col-md10 layui-col-xs10">
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">商品状态：</label>
									<div class="layui-input-inline">
										<select name="status" class="on_off" lay-filter='goods_status'></select>
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">商品类型：</label>
									<div class="layui-input-inline">
										<select name="type" class="goods_type" lay-filter='goods_type'></select>
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">商品编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" name="skuid" placeholder="商品编号"
											autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">产品编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" name="spuid" placeholder="产品编号"
											autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">商品、店铺名称：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" name="keywords" placeholder="商品、店铺名称"
											autocomplete="off">
									</div>
								</div>

								<div class="layui-inline search_inline">
									<label class="layui-form-label">店铺：</label>
									<div class="layui-input-inline" style="min-width: 90px;">
										<div class="choose_shopname" id="choose_shopname">未选择</div>
										<input type="hidden" name="sub_shopid" class="layui-input"
											lay-verify="sub_shopid">
										<input type="hidden" name="sub_shopname" class="sub_shopname"
											lay-verify="sub_shopname">
									</div>
									<div class="layui-input-inline">
										<button type="button" class="layui-btn" onclick="chooseShop()">选择店铺</button>
									</div>
								</div>

								<button class="layui-btn search_inline" lay-submit="" lay-filter="search"
									data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->
							<table id="test-table-operate" lay-filter="test-table-operate"></table>

							<script type="text/html" id="test-table-operate-barDemo">
								{{# if(d.status != -1) {}}
								<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
								{{# }}}
								{{# if(d.status == -1) {}}
								<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="audit">审核</a>
								{{# }}}
								{{# if(d.status == 0 || d.status == -1) {}}
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
								{{# }}}
							</script>
						</div>
					</div>
				</div>
			</div>
			<!--商品信息模板-->
			<!-- 主图 -->
			<script type="text/html" id="test-table-operate-img">
				<img src={{d.goods_image_url}} />
			</script>
			<!-- 视频 -->
			<script type="text/html" id="test-table-operate-video">
				<video>
					<source src="{{d.video_url}}">
					</source>
				</video>
			</script>

			<!-- 价格 -->
			<script type="text/html" id="test-table-operate-price">
				<div class="tDiv">
					<!-- 原价 -->
					<!-- 会员价 -->
					会员价：
					<span class="line-text"> {{ d.price_member ? '￥' + d.price_member : ''}}</span>
					<br />
					直推佣金：
					<span class="line-text"> {{ d.direct_fee ? '￥' + d.direct_fee   : ''}}</span>
					<br />
					间推佣金：
					<span class="line_text"> {{ d.indirect_fee ? '￥' + d.indirect_fee   : ''}}</span>
					<br />
					团长佣金：
					<span class="line_text"> {{ d.leader_fee ? '￥' + d.leader_fee   : ''}}</span>
					<br />
					团队佣金：
					<span class="line_text"> {{ d.team_fee ? '￥' + d.team_fee   : ''}}</span>
					<br />
					合伙人佣金：
					<span class="line-text"> {{ d.copartner_fee ? '￥' + d.copartner_fee : ''}}</span>
					<br />
					服务站佣金：
					<span class="line-text"> {{ d.station_fee ? '￥' + d.station_fee : ''}}</span>
					<br />
					赠送积分：
					<span class="line-text"> {{ d.give_score ? d.give_score : ''}}</span>
				</div>
			</script>
			<!-- 商品信息 -->
			<script type="text/html" id="test-table-operate-goods">
				<div class="tDiv">
					商品名称：
					<span class="line-text"> {{ d.skuname ? d.skuname : ''}}</span>
					<br />
					商品简称：
					<span class="line-text"> {{ d.title ? d.title : ''}}</span>
					<br />
					<!--计量单位： 
					<span class="line-text"> {{ d.measure_unit ? d.measure_unit : ''}}</span>
			 		<br/>-->
					规格名称：
					<span class="line-text"> {{ d.specname ? d.specname : ''}}</span>
					<br />
					规格参数：
					<span class="line-text"> {{ d.specparam ? d.specparam : ''}}</span>
					<br />
					分期：
					<span class="line_text"> {{ d.fq ? d.fq   : ''}}</span>
				</div>
			</script>
			<script type="text/html" id="zizeng">
			{{d.LAY_TABLE_INDEX+1}}
			</script>

			<script src="../../../layuiadmin/layui/layui.js"></script>
			<script src="../../../js/common.js" type="text/javascript" charset="utf-8"></script>
			<script>
				layui.config({
					base: '../../../layuiadmin/' //静态资源所在路径
				}).extend({
					index: 'lib/index' //主入口模块
				}).use(['index', 'table', 'tree', 'excel'], function() {
					var $ = layui.$,
						form = layui.form,
						tree = layui.tree,
						excel = layui.excel,
						table = layui.table;
						
					var _data = {};
					var _data1 = {};
					var maplist = JSON.parse(localStorage.getItem('lsmap'))
					goods_status_show('option')
					on_off_show('option')

					goods_type_show("option")

					initLeftTreeData()

					function initLeftTreeData() {
						$.get(server.queryproduct_tree, {id: 0}, function(res, status) {
							if(status == 'success') {
								if(res.code == 0) {
									var data = res.product_category.data
									data[0].spread = true;
									data[0].children[0].spread = true;
									//开启节点操作图标
									tree.render({
										elem: '#test9',
										data: data,
										onlyIconControl: true,
										click: function(obj) {
											var data = obj.data
											_data.cat_id = data.id == 1 ? '' : data.id
											_data.name = data.title 
											initdata();
										},
										accordion: true 
									});
								} else {
									layer.msg(res.msg);
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}
				
					initdata();

					function initdata() {
						table.render({
							elem: '#test-table-operate',
							url: server.querygoods,
							height: 'full-150',
							//totalRow: true,
							cols: [
								[{
										type: 'checkbox',
										fixed: 'left',
										width: 50,
									}, {
										width: 50,
										field: 'zizeng',
										title: '#',
										fixed: 'left',
										templet: '#zizeng'
									}, {
										width: 180,
										align: 'center',
										toolbar: '#test-table-operate-barDemo',
										title: '操作',
										totalRowText: '合计：',
										fixed: 'left'
									}, {
										width: 100,
										align: 'center',
										toolbar: '#test-table-operate-img',
										title: '主图',
									}, {
										field: 'status',
										width: 120,
										title: '商品状态',
										templet: function(d) {
											var html = ''
											for (var i = 0; i < maplist.on_off.length; i++) {
												if (maplist.on_off[i].value == String(d.status)) {
													html = '<input type="checkbox" name="status" value=' + d
														.skuid +
														' lay-skin="switch" lay-text="启用|停用" lay-filter="status" checked>'
												} else {
													html = '<input type="checkbox" name="status" value=' + d
														.skuid +
														' lay-skin="switch" lay-text="启用|停用" lay-filter="status">'
												}
											}
											return html;
										}
									}, {
										field: 'recommend',
										width: 120,
										title: '商品推荐状态',
										templet: function(d) {
											var html = ''
											for (var i = 0; i < maplist.on_off.length; i++) {
												if (maplist.on_off[i].value == String(d.recommend)) {
													html = '<input type="checkbox" name="status" value=' + d
														.skuid +
														' lay-skin="switch" lay-text="开|关" lay-filter="recommend" checked>'
												} else {
													html = '<input type="checkbox" name="status" value=' + d
														.skuid +
														' lay-skin="switch" lay-text="开|关" lay-filter="recommend">'
												}
											}
											return html;
										}
									}, {
										field: 'client',
										width: 180,
										title: '客户端',
										templet: function(d) {
											var client = d.client;
											if (client) {
												var client_leng = client.split(',');
												var client_show = ''
												for (var i = 0; i < client_leng.length; i++) {
													client_show += icon_type_show(1, client_leng[i]) + ','
												}
												return client_show
											} else {
												return ''
											}
										}
									}, {
										field: 'type',
										width: 100,
										title: '商品类型',
										templet: function(d) {
											return String(d.type) ? goods_type_show(1, d.type) : ''
										}
									}, {
										field: 'skuid',
										width: 90,
										title: '商品编号'
									},
									{
										field: 'channelname',
										width: 90,
										title: '频道'
									},
									{
										field: 'sub_shopname',
										width: 200,
										title: '店铺'
									},
									{
										field: 'categoryname',
										width: 200,
										title: '分类'
									},

									{
										field: 'spuid',
										width: 90,
										title: '产品编号'
									},
									/*{
																		field: 'level', 
																		title: '专属等级', 
																		width: 120,
																		templet: function(d) {
																			return String(d.level) ? site_union_show(1,d.level):'';
																		}
																	},*/
									{
										field: 'price_member',
										width: 250,
										title: '商品规格信息',
										toolbar: "#test-table-operate-goods"
									}, {
										field: 'low_quantity',
										width: 250,
										title: '最低数量',
										toolbar: "#test-table-operate-goods"
									}, {
										field: 'price_member',
										width: 150,
										title: '价格',
										toolbar: "#test-table-operate-price"
									},
									/*   {
																		field: 'score_scale',
																		width: 120,
																		title: '积分使用比例',
																		totalRow: true,
																		sort:true
																	},  {
																		field: 'score',
																		width: 120,
																		title: '积分使用',
																		totalRow: true,
																		sort:true
																	},*/
									{
										field: 'stock',
										width: 100,
										title: '当前库存',
										totalRow: true
									}, {
										field: 'sales',
										width: 100,
										title: '销量',
										totalRow: true
									}, {
										field: 'support',
										width: 160,
										title: '店铺信息',
									},
									/*{
																		field: 'brand_name',
																		width: 160,
																		title: '品牌名称',
																	},*/
									{
										field: 'examples_img_url',
										width: 120,
										title: '示例图片',
										templet: function(d) {
											return d.examples_img_url ?
												'<a class="text_blue_color" href="javascript:;" lay-event="seeimgexamples">查看示例图片</a>' :
												''
										}
									}, {
										field: 'goods_image_url',
										width: 120,
										title: '主图',
										templet: function(d) {
											return d.goods_image_url ?
												'<a class="text_blue_color" href="javascript:;" lay-event="seeimgzhu">查看主图</a>' :
												''
										}
									}, {
										field: 'goods_gallery_urls',
										width: 100,
										title: '轮播图',
										templet: function(d) {
											return d.goods_gallery_urls ?
												'<a class="text_blue_color" href="javascript:;" lay-event="seeimglunbo">查看轮播图</a>' :
												''
										}
									}, {
										field: 'video_url',
										width: 160,
										title: '视频链接',
										//toolbar:"#test-table-operate-video"
										templet: function(d) {
											return d.video_url ?
												'<a class="text_blue_color" href="javascript:;" lay-event="seevideo">查看视频</a>' :
												''
										}
									}, {
										field: 'video_cover',
										width: 120,
										title: '视频封面',
										templet: function(d) {
											return d.video_cover ?
												'<a class="text_blue_color" href="javascript:;" lay-event="seeivideo_cover">查看视频封面</a>' :
												''
										}
									}, {
										field: 'add_by',
										width: 100,
										title: '创建人',
									}, {
										field: 'addtime',
										width: 160,
										title: '创建时间',
									}, {
										field: 'edit_by',
										width: 100,
										title: '更新人',
									}, {
										field: 'edittime',
										width: 160,
										title: '更新时间',
									}
								]
							],
							page: true,
							where: _data,
							limit: limit,
							limits: limits,
							request: {
								pageName: 'page',
								limitName: 'size',
							},
							parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
								return {
									"code": res.code, //解析接口状态
									"msg": res.msg, //解析提示文本
									"count": res.goods_list.pager.total, //解析数据长度
									"data": res.goods_list.data //解析数据列表
								};
							},
							done: function() {
								//lay-tree的颜色 
								var nodes = document.getElementsByClassName("layui-tree-txt");
								for (var i = 0; i < nodes.length; i++) {
									if (nodes[i].innerHTML === _data.name)
										nodes[i].style.color = "red";
									else
										nodes[i].style.color = "#555";
								}
							},
						});
					}
					//监听搜索
					form.verify({
						memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
							if (!value) {
								return '姓名不能为空';
							}
						}
					});

					//监听搜索
					form.on('submit(search)', function(data) {
						<!-- _data = data.field -->
						Object.assign(_data, data.field)
						initdata();
						return false;
					});

					$("button[type=reset]").on("click", function() {
						_data = {}
						initdata();
						document.getElementById("form").reset();
						$('input[name=sub_shopid]').val('店铺未选择');
					});
					//监听工具条
					table.on('tool(test-table-operate)', function(obj) {
						var data = obj.data;
						console.log('=============');
						console.log(obj);
						
						if (obj.event === 'edit' || obj.event === 'audit') {
							var addOrEditParams = '&skuid=' + data.skuid + '&handleEvent=' + obj.event
							layer.open({
								type: 2,
								title: obj.event === 'edit' ? '修改商品' : '审核商品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: '../model/edit_add.html?skuid=' + data.skuid + '&handleEvent=' + obj.event,
								// content: getAuthVueRequestUrl('/shop_manage/goods_manage/add_edit', addOrEditParams),
								end: function() {}
							});
						} else if (obj.event === 'del') {
							var data = obj.data;
							var skuid = data.skuid
							layer.confirm('确定要删除该商品？', function(index) {

								submitDelete(skuid, 0)

							}, function() {
								initdata();
								layer.msg('取消操作');
							});

						} else if (obj.event === 'seeimgzhu') {
							var img_data = {
								"data": [{
									"src": data.goods_image_url
								}]
							}
							layer.photos({
								photos: img_data,
								anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							});
						} else if (obj.event === 'seeimglunbo') {
							console.log("打印下");
							if (data.goods_gallery_urls) {
								var imgarr = data.goods_gallery_urls.split(',');
							}

							var img_data = {
								"data": []
							}
							for (var i = 0; i < imgarr.length; i++) {
								img_data.data.push({
									"src": imgarr[i]
								})
							}
							layer.photos({
								photos: img_data,
								anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							});
						} else if (obj.event === 'seeivideo_cover') {
							if (data.video_cover) {
								var imgarr = data.video_cover.split(',');
							}

							var img_data = {
								"data": []
							}
							for (var i = 0; i < imgarr.length; i++) {
								img_data.data.push({
									"src": imgarr[i]
								})
							}
							layer.photos({
								photos: img_data,
								anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							});
						} else if (obj.event === 'seevideo') {
							layer.open({
								type: 1,
								//title: '修改客户资料',
								title: '',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['80%', '80%'],
								content: '<video style="width:100%;height:100%" controls="controls" id=' +
									data.id + ' width="320" height="240"><source src=' + data.video_url +
									' type="video/ogg" /><source src=' + data.video_url +
									' video/mp4" /></video>',
							});
						} else if (obj.event === 'seeimgexamples') {
							var img_data = {
								"data": [{
									"src": data.examples_img_url
								}]
							}
							console.log(img_data);
							layer.photos({
								photos: img_data,
								anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机
							});
						}
					});

					form.on('switch(status)', function(obj) {
						var skuid = this.value;
						layer.confirm('确定要修改状态？', function(index) {
							if (obj.elem.checked) {
								submitdata(skuid, 1)
							} else {
								submitdata(skuid, 0)
							}
						}, function() {
							initdata();
							layer.msg('取消操作');
						});

					});
					form.on('switch(recommend)', function(obj) {
						var skuid = this.value;
						layer.confirm('确定要修改推荐状态？', function(index) {
							if (obj.elem.checked) {
								submit_recommend(skuid, 1)
							} else {
								submit_recommend(skuid, 0)
							}
						}, function() {
							initdata();
							layer.msg('取消操作');
						});

					});

					// 选择子店铺
					window.chooseShop = function() {
						layer.open({
							type: 2,
							title: '选择店铺',
							shadeClose: false,
							shade: 0.5,
							maxmin: false, //开启最大化最小化按钮
							area: ['90%', '90%'],
							content: '../model/choose_shop_id.html',
							end: function() {},
							success: function(layer, index) {}
						});
					}
					window.selectShop = function(data) {
						if (data && data.length) {
							data = data[0];
							$('input[name=sub_shopid]').val(data.sub_shopid);
							$('input[name=sub_shopname]').val(data.sub_shopname);
							$('#choose_shopname').html(data.sub_shopname);
						}
					}

					function submit_recommend(skuid, recommend) {
						$.post(server.updategoods, {
							skuid: skuid,
							is_recommend: recommend
						}, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) {
									layer.alert('操作成功', function() {
										layer.closeAll();
										initdata();
									});
								} else {
									layer.msg(res.msg);
									layer.closeAll('loading');
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}

					function submitdata(skuid, status) {
						$.post(server.updategoods, {
							skuid: skuid,
							status: status
						}, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) {
									layer.alert('操作成功', function() {
										layer.closeAll();
										initdata();
									});
								} else {
									layer.msg(res.msg);
									layer.closeAll('loading');
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}

					function submitDelete(skuid) {
						$.post(server.deletegoods, {
							skuid: skuid
						}, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) {
									layer.alert('操作成功', function() {
										layer.closeAll();
										table.reload('test-table-operate');
									});
								} else {
									layer.msg(res.msg);
									layer.closeAll('loading');
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}

					function del_goods() {
						var checkStatus = table.checkStatus('test-table-operate'),
							data = JSON.stringify(checkStatus.data);
						var skuid = "";
						for (var i = 0; i < checkStatus.data.length; i++) {
							skuid += checkStatus.data[i].skuid;
							if (i != checkStatus.data.length - 1) {
								skuid += ",";
							}
						}
						layer.confirm('确定要删除所选的' + checkStatus.data.length + '条数据？', function() {
							$.ajax({
								url: server.deletegoods,
								type: 'post',
								dataType: 'json',
								data: {
									skuid: skuid
								},
								success: function(data) {
									if (data.code == '0') {
										layer.msg('操作成功');
										initdata();
									} else {
										layer.msg('操作失败');
										initdata();
									}
								},
								'error': function() {
									layer.msg('系统错误');
									initdata();
								}
							})
						});
					}

					function edit_status(status, msg) {
						var checkStatus = table.checkStatus('test-table-operate'),
							data = JSON.stringify(checkStatus.data);
						var id = "";
						for (var i = 0; i < checkStatus.data.length; i++) {
							id += checkStatus.data[i].id;
							if (i != checkStatus.data.length - 1) {
								id += ",";
							}
						}
						layer.confirm('确定要' + msg + '所选的' + checkStatus.data.length + '条数据？', function() {
							$.ajax({
								url: server.onoffgoods,
								type: 'post',
								dataType: 'json',
								data: {
									id: id,
									status: status
								},
								success: function(data) {
									if (data.code == '0') {
										layer.msg(msg + '成功');
										initdata();
									} else {
										layer.msg(msg + '失败');
										initdata();
									}
								},
								'error': function() {
									layer.msg('系统错误');
									initdata();
								}
							})
						});
					}

					function copy() {
						$.post(server.copygoods, {}, function(res, status) {
							if (status == 'success') {
								if (res.code == 0) {
									layer.alert('操作成功', function() {
										layer.closeAll();
										table.reload('test-table-operate');
									});
								} else {
									layer.msg(res.msg);
									layer.closeAll('loading');
								}
							} else {
								layer.msg('服务器连接错误');
							}
						});
					}

					function edit_recommend(status, msg) {
						var checkStatus = table.checkStatus('test-table-operate'),
							data = JSON.stringify(checkStatus.data);
						var id = "";
						for (var i = 0; i < checkStatus.data.length; i++) {
							id += checkStatus.data[i].id;
							if (i != checkStatus.data.length - 1) {
								id += ",";
							}
						}
						layer.confirm('确定要' + msg + '所选的' + checkStatus.data.length + '条数据？', function() {
							$.ajax({
								url: server.onoffgoods,
								type: 'post',
								dataType: 'json',
								data: {
									id: id,
									is_recommend: status
								},
								success: function(data) {
									if (data.code == '0') {
										layer.msg(msg + '成功');
										initdata();
									} else {
										layer.msg(msg + '失败');
										initdata();
									}
								},
								'error': function() {
									layer.msg('系统错误');
									initdata();
								}
							})
						});
					}
					
					
					$('#importbill').on('click', function () {
						var htmlContent = '<div style="width:100%;height:100%;text-align: center;">'
						htmlContent += '<p>下载导入模板</p>';
						htmlContent += '<div class="layui-upload-drag" id="importData" >';
						htmlContent += '<input multiple="multiple" type="file" style="cursor:pointer;opacity: 0.0; position: absolute; top: 0; left: 0; bottom: 0; right: 0; width: 100%; height:100%;">';
						htmlContent += '<i class="layui-icon"></i>';
						htmlContent += '<p id="filename">点击选择文件，或将文件拖拽到此处，支持多文件导入</p>';
						htmlContent += '</div>';
						htmlContent += '<div ">';
						//htmlContent += '<button id="downloadFiles" class="layui-btn" style="margin-top:10px;margin-bottom:10px;">下载模板</button>';
						htmlContent += '</div>';
						htmlContent += '</div>';
						layer.open({
							type: 1
							, offset: "auto"
							, id: 'layer_importData'
							, title: '导入'
							, area: '400px'
							, content: htmlContent    //需要打开的模板
							, btnAlign: 'c' //按钮居中
							, shade: 0 //不显示遮罩
							, success: function (layero, index) {
								console.log(layero,'layero')
								// 监听上传文件的事件
								$('#importData').change(function (e) {
									var files = e.target.files;
									uploadExcel(files);
									
								});
								//下载模板
							}

						});
					});
					function uploadExcel(files) {
						// const importLoading = layer.load(0, {
						// // shade: [0.4, '#000'], //0.4为透明度 ，#000 为颜色
						// })
						try {
							// for (let i = 0; i < files.length; i++) {
							// 	 files[i].name = files[i].name + 'test';
							// }
							excel.importExcel(files, {
								// 读取数据的同时梳理数据
								/**
								fields: {
									'cash_id': 'A'//编号
									, 'card_no': 'B'//收款账户
									, 'card_name': 'C'//收款人名称
									, 'cert_no': 'D'//收款人身份证号
									, 'mobile': 'E'//收款人手机号
									, 'branch_name': 'F'//开户行支行名称
									, 'area_province': 'G'//收款人所在省
									, 'area_city': 'H'//收款人所在市
									, 'cash_amt': 'I'//金额
									, 'notes': 'J'//用途（附言）
									, 'user_id': 'K'//用户ID
									, 'dates': 'L'//申请时间
									, 'money_type': '打款类型' // 打款类型
								}
								*/
							}, function (data) {
								console.log("🚀 ~ file: list.html:776 ~ uploadExcel ~ data:", data)
								console.log("🚀 ~ file: list.html:776 ~ uploadExcel ~ files:", files)
								const fields = {
									"分类": "catname",
									"产品状态": "status",
									"商品类型": "type",
									"客户端类型": "client",
									"产品名称": "spuname",
									"商品名称": "skuname",
									"分期": "fq",
									"频道编号": "channelid",
									"频道名称": "channelid_name",
									"选择店铺id": "sub_shopid",
									"选择店铺": "sub_shopname",
									"是否推荐": "is_recommend",
									"能否加入购物车": "cart",
									"商品简称": "title",
									"点击量": "hits",
									"计量单位": "measure_unit",
									"赠送积分": "give_score",
									"积分抵扣": "score",
									"专属等级": "level",
									"赠送等级": "grade",
									"赠送月份": "grade_month",
									"商品运费": "price_waybill",
									"发货说明": "instructions",
									"最低购买数量": "low_quantity",
									"直推佣金": "direct_fee",
									"间推佣金": "indirect_fee",
									"团长佣金": "leader_fee",
									"管理奖": "team_fee",
									"合伙人佣金": "copartner_fee",
									"服务站佣金": "station_fee",
									"规格名称": "specname",
									"规格参数": "specparam",
									"商品简介": "intro",
									"售后保障": "support",
									"商品示例图": "examples_img_url",
									"商品主图": "goods_image_url",
									"商品轮播图": "goods_gallery_urls",
									"视频": "video_url",
									"视频封面": "video_cover",
									"成本价": "cost_price",
									"原价": "price",
									"会员价": "price_member",
									"库存": "stock",
								}
								for (let f = 0; f < files.length; f++) {
									// alert(filename);
									// console.log(filename,'filename0000')
									// let rows = data['0']['Sheet1'];

									for(var k in data[f]) {
										let rows = data[f][k];
										let filename = files[f].name.replace('.xlsx', '').replace('.xls', '');
										if (k.indexOf('sheet') == -1) {
											filename +='_'+k;
										}
										// 表格数据处理为想要的字段，例如：{"area_city":"收款人所在市","area_province":"收款人所在省","branch_name":"开户行支行名称","card_name":"收款人名称","card_no":"收款账户","cash_amt":"金额","cash_id":"编号","cert_no":"收款人身份证号","dates":"申请时间","mobile":"收款人手机号","money_type":"打款类型","notes":"用途（附言）","user_id":"用户ID"}
										if (rows && rows.length) {
											const valueFields = {};
											const row = Object.values(rows[0]);
											if (row[0] === '分类') {
												row.forEach((field, index) => {
													console.log(fields[field],field,index,"===========")
													valueFields[index] = fields[field];
												});
											}
											rows = rows.map((row, index) => {
												let rowValues = {};
												Object.values(row).forEach((item, index) => {
													rowValues[valueFields[index]] = item;
													return item;
												});
												return rowValues;
											});
										}

										// if(rows.length>0){
										// 	if(rows[0].spuStatus=='商品状态'&&rows[0].card_name=='收款人名称'&&rows[0].card_no=='收款账户'&&rows[0].cert_no=='收款人身份证号'&&rows[0].cash_amt=="金额"){
												
										// 	}else{
										// 		layer.msg('导入数据格式错误');
										// 		layer.close(importLoading)
										// 		return;
										// 	}
										// }
										
										if(rows.length>0){
											for (let i = 0; i < rows.length; i++) {
												if(!rows[i].skuname  && !rows[i].title && !rows[i].low_quantity && !rows[i].hits && !rows[i].catid && !rows[i].cost_price && !rows[i].price && !rows[i].price_member && !rows[i].discount && !rows[i].price_member){
													layer.msg('导入数据格式错误');
													return;
												}
											}
										}

										let billdata = [];	
										if (rows.length > 0) {
											for (let i = 1; i < rows.length; i++) {
												let row = rows[i];
												let flg = true;
												for (let p in row) {
													row[p] = ('' + row[p]).trim()
													if (p == 'dates') {
														row[p] = row[p].substring(0, 10)
													}else if(p == 'cert_no'){
														if(row[p]==null||row[p]==''){
															flg = false;
														}
													}
												}
												if(flg){
													billdata.push(row);
												}
											}
										}
										for(var i=0;i<billdata.length;i++){
											if(billdata[i].spuStatus==''){
												layer.msg('导入数据不能为空');
												break;
											}
										}
										if (billdata && billdata.length) {
											let _data = {
												groupname: filename
												, billdata: JSON.stringify(billdata)
											};
											// let importLoading = null;
											// setTimeout(() => {
											// 	importLoading = layer.load(0, {
											// 		// shade: [0.4, '#000'], //0.4为透明度 ，#000 为颜色
											// 	})
											// }, 10)
											console.log("看看提交的数据",_data,JSON.parse(_data.billdata));
											sessionStorage.setItem("datalist",_data.billdata)
											// $.post(server.sys_shop_cash_out_insert, _data, function (res, status) {
											// 	console.log("看看提交的数据", server.sys_shop_cash_out_insert, _data);
											// 	if (status == 'success') {
											// 		if (res.code == 0) {
											// 			// console.log("修改成功后的", res);
											// 			layer.msg('导入成功');
											// 			// layer.alert('操作成功', function() {
											// 			// 	parent.layer.closeAll();
											// 			// });
											// 			initdata()
											// 		} else {
											// 			layer.msg(res.msg);
											// 		}
											// 		layer.close(importLoading)
											// 		//closeloading();
											// 	} else {
											// 		//closeloading();
											// 		layer.close(importLoading)
											// 		layer.msg('服务器连接错误');
											// 	}
											// });
										}

									}
								}
								layer.closeAll();
								layer.open({
												type: 2,
												title: '列表',
												shadeClose: false,
												shade: 0.5,
												maxmin: true, //开启最大化最小化按钮
												area: ['90%', '90%'],
												content: '../model/spimportlist.html?datalist=22',
												// content: '../model/spimportlist.html',
												// content: '../model/edit_add.html?skuid=' + data.skuid + '&handleEvent=' + obj.event,
												// content: getAuthVueRequestUrl('/shop_manage/goods_manage/add_edit', addOrEditParams),
												end: function() {}
											});
								
							});
						} catch (e) {
							layer.alert(e.message);
						}
					}


					//事件
					var active = {
						batchdel: function() {
							var checkStatus = table.checkStatus('LAY-user-back-role'),
								checkData = checkStatus.data; //得到选中的数据
							if (checkData.length === 0) {
								return layer.msg('请选择数据');
							}
							layer.confirm('确定删除吗？', function(index) {
								table.reload('LAY-user-back-role');
								layer.msg('已删除');
							});
						},
						alladd: function() {
							layer.open({
								type: 2,
								title: '添加商品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: '../model/edit_add.html?cat_id=' + (_data.cat_id || '') + '&cat_name=' + (_data.name || ''),
								success: function(layero, index) {
									var iframe = window['layui-layer-iframe' + index]
									iframe.child(_data, index)
								},
								end: function() {}
							});
						},
						on: function() {
							edit_status(1, "启用")
						},
						off: function() {
							edit_status(0, "禁用")
						},
						on_recommend: function() {
							edit_recommend(1, "推荐")
						},
						off_recommend: function() {
							edit_recommend(0, "取消推荐")
						},
						edit: function() {
							layer.open({
								type: 2,
								title: '修改产品',
								shadeClose: false,
								shade: 0.5,
								maxmin: true, //开启最大化最小化按钮
								area: ['90%', '90%'],
								content: '../model/active_edit_audit.html',
								success: function(layero, index) {
									var checkStatus = table.checkStatus('test-table-operate'),
										data = JSON.stringify(checkStatus.data);
									var id = "";
									var skuid = "";
									for (var i = 0; i < checkStatus.data.length; i++) {
										id += checkStatus.data[i].id;
										skuid += checkStatus.data[i].skuid;
										if (i != checkStatus.data.length - 1) {
											id += ",";
											skuid += ",";
										}
									}
									var _datas = {}
									_datas.id = id;
									_datas.skuid = skuid
									var iframe = window['layui-layer-iframe' + index]
									iframe.child(_datas, index)
								},
								end: function() {

								}
							});
						},
						del: function() {
							del_goods()
						},
						copy: function() {
							copy();
						}
					}
					$('.table-operate-btn .layui-btn').on('click', function() {
						var type = $(this).data('type');
						active[type] ? active[type].call(this) : '';
					});
				});
			</script>
	</body>

</html>